// Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files. // The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. // *********/ // Pin connected to the LED const int ledPins[] = {2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17}; // Time interval between brightness steps (in milliseconds) const int fadeInterval = 50; // Maximum and minimum brightness values const int maxBrightness = 220; const int minBrightness = 60; // Direction flag for fading (true = increasing, false = decreasing) bool fadingDirection = true; void setup() { // Initialize each LED pin as an output for (int i = 0; i < sizeof(ledPins) / sizeof(ledPins[0]); i++) { pinMode(ledPins[i], OUTPUT); } } void fade() { // for (int j = 0; j < sizeof(ledPins) / sizeof(ledPins[0]); j++) { // analogWrite(ledPins[j], 255); // } // delay(5000); // Update the brightness value based on the fading direction if (fadingDirection) { for (int i = minBrightness; i <= maxBrightness; i++) { Serial.println(i); // Set the LED brightness for each pin for (int j = 0; j < sizeof(ledPins) / sizeof(ledPins[0]); j++) { analogWrite(ledPins[j], i); } // Delay for the fade interval delay(fadeInterval); } fadingDirection = false; } else { for (int i = maxBrightness; i >= minBrightness; i--) { Serial.println(i); // Set the LED brightness for each pin for (int j = 0; j < sizeof(ledPins) / sizeof(ledPins[0]); j++) { analogWrite(ledPins[j], i); } // Delay for the fade interval delay(fadeInterval); } fadingDirection = true; } } void loop() { fade(); }